package com.ldzy.controller;

import com.ldzy.pojo.Shopping;
import com.ldzy.service.IShoppingService;
import com.ldzy.utilts.RespUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/Shopping")
public class ShoppingController {
    @Resource
    IShoppingService iShoppingService;
    @PostMapping("findByUserCakeId")
    public RespUtil findByUserCakeId(@RequestBody Shopping shopping){
        return  iShoppingService.findByUser_Cake_id(shopping);
    }
    @PutMapping ("/updateNumber")
    public RespUtil updateNumber(@RequestBody Shopping shopping){
        if (iShoppingService.isFindBy(shopping)){
            if (iShoppingService.updateNumber(shopping)){
                return RespUtil.success(iShoppingService.findByUser_Cake_id(shopping));
            }
        }
        else {
            shopping.setNumber(1);
            if (iShoppingService.save(shopping))
                return RespUtil.success(iShoppingService.findByUser_Cake_id(shopping));
        }
        return  RespUtil.error("系统错误!!!");
    }
        @GetMapping("/findShopping")
    public  RespUtil findShopping(Shopping shopping){
        return  iShoppingService.findShopping(shopping);
    }
    @PostMapping("/deleteOrder")
    public RespUtil deleteOrder(@RequestBody Shopping shopping){
        return  iShoppingService.deleteOrder(shopping);
    }
    @PutMapping("/updateNumberChange")
    public RespUtil updateNumberChange(@RequestBody Shopping shopping){
        return  iShoppingService.updateNumberChange(shopping);
    }
}
